package cn.webestar.scms.api.vo.department;

import cn.webestar.scms.user.entity.Department;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;

import java.util.Date;
import java.util.List;

@Data
@Schema(name = "DepartmentVO", description = "部门")
public class DepartmentVO {

    @Schema(description = "主键")
    private Long id;

    @Schema(description = "租户id")
    private Long cid;

    @Schema(description = "父部门")
    private Long pid;

    @Schema(description = "排序号")
    private Integer sort;

    @Schema(description = "部门编码")
    private String no;

    @Schema(description = "部门名称")
    private String name;

    @Schema(description = "创建时间")
    private Date createTime;

    @Schema(description = "状态，0：禁用，1：启用")
    private Integer status;

    @Schema(description = "备注")
    private String remark;

    @Schema(description = "子部门")
    private List<DepartmentVO> children;

    public static DepartmentVO convert(Department dep) {
        DepartmentVO vo = new DepartmentVO();
        vo.setId(dep.getId());
        vo.setCid(dep.getCid());
        vo.setPid(dep.getPid());
        vo.setSort(dep.getSort());
        vo.setNo(dep.getNo());
        vo.setName(dep.getName());
        vo.setCreateTime(dep.getCreateTime());
        vo.setStatus(dep.getStatus());
        vo.setRemark(dep.getRemark());
        return vo;
    }

    public static List<DepartmentVO> convertToList(List<Department> deps) {
        return deps.stream().map(DepartmentVO::convert).toList();
    }

}